package com.linjm.manageweb.controller;

import com.linjm.bean.*;
import com.linjm.service.SpuService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class SpuController {
    @DubboReference
    private SpuService spuService;
    @RequestMapping("spuList")
    //localhost:8082/spuList?catalog3Id=1
    public List<SpuInfo> getSpuList(SpuInfo spuInfo){
        return spuService.getSpuList(spuInfo);
    }

    @RequestMapping("saveSpuInfo")
    public String saveSpuInfo(@RequestBody SpuInfo spuInfo){
        spuService.saveSpuInfo(spuInfo);
        return "ok";
    }

    //http://localhost:8082/spuImageList?spuId=5
    @RequestMapping("spuImageList")
    public List<SpuImage> getSpuImageList(SpuImage spuId){
        return spuService.getSpuImageList(spuId);
    }

    //localhost:8082/spuSaleAttrList?spuId=59
    @RequestMapping("spuSaleAttrList")
    public List<SpuSaleAttr> getSpuSaleAttrList(String spuId){
        return spuService.getSpuSaleAttrList(spuId);
    }

    @RequestMapping("saveSkuInfo")
    public void saveSkuInfo(@RequestBody SkuInfo skuInfo){
        if(skuInfo!=null){
            spuService.saveSkuInfo(skuInfo);
        }
    }

    @RequestMapping("sku")
    public String skuTest(String skuId){
        SkuInfo skuInfo = spuService.getSkuInfo(skuId);
        return skuInfo.toString();
    }
}
